package com.huaxinkaiye.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;

import android.util.Log;

public class analysisCar {
	
	public static String main(String pic) {	
		  String   data = null;
		//File dir = new File("D:\\plates\\");
		 //for (File f : dir.listFiles()) {
			try {
				//System.out.println("Analysing " + f);
//				HttpPost post = new HttpPost("http://222.128.120.189:8081/qcbfhs2/car/pic/analysis");
				HttpPost post = new HttpPost("http://222.128.120.189:8081/qccjservice/car/pic/analysis");
				Log.e("JSESSIONID_jiexitupian",SimpleClient.JSESSIONID );
				//post.setHeader("Cookie", "JSESSIONID=" + SimpleClient.JSESSIONID);
				List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
								
				//String imageStr = ImageUtil.GetImageStr(f.getAbsolutePath());	
				String imageStr = ImageUtil64Code.GetImageStr(pic);	
				urlParameters.add(new BasicNameValuePair("pic", imageStr));

				post.setEntity(new UrlEncodedFormEntity(urlParameters));
				//HttpClient client = HttpClients.createDefault();
				HttpClient client = new DefaultHttpClient();
//				  // 请求超时
//				client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
//	            // 读取超时
//				client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 30000);
				HttpResponse response = client.execute(post);			
			    data=consume(response);
			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			 return data;
		}
	//}
	
	private static String consume(HttpResponse response) throws IOException {
		System.out.println("Response Code : " 
	                + response.getStatusLine().getStatusCode());

		BufferedReader rd = new BufferedReader(
		        new InputStreamReader(response.getEntity().getContent()));

		StringBuffer result = new StringBuffer();
		String line = "";
		while ((line = rd.readLine()) != null) {
			result.append(line);
		}
		Log.e("result---", result.toString());
		return result.toString();
		//System.out.println(result);	
	}
}
